package com.szholly.data.general;

import java.util.HashMap;

import org.springframework.stereotype.Component;

import com.szholly.utils.util.StringUtils;
import com.szholly.data.cache.DomainCache;
import com.szholly.data.cache.MetadataDataCache;

/**
 * 类功能说明 定义定义元数据管理工作空间类 2014.6.5
 */
@Component("TableFactory")
public class TableFactoryClass implements ITableFactory {

	/**
	 * 打开指定结构表
	 */
	public ITable openTable(String metadataTableName) {
		if (StringUtils.IsNullOrSpace(metadataTableName))
			return null;

		metadataTableName = metadataTableName.toUpperCase().trim();
		
		HashMap<String, ITable> tableCache = MetadataDataCache.getTableCache();
		if (tableCache == null) {
			MetadataDataCache.init();
			tableCache = MetadataDataCache.getTableCache();
		}
		if (tableCache.containsKey(metadataTableName)) {
			ITable pTable = tableCache.get(metadataTableName);
			return pTable;
		} else {
			return null;
		}
	}

	@Override
	public IDomain openDomain(String codeTableName, String codeDomainName) {
		return DomainCache.getDomain(codeTableName, codeDomainName);
	}
}